package ui.face {

	import com.greensock.plugins.VolumePlugin;
	
	import common.loader.Info;
	import common.loader.LoaderManager;
	import common.loader.LoaderType;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	
	import globals.Global;
	
	import ui.component.Label;
	
	public class UserFace extends Sprite {
		
		private var nameLabel:Label;
		private var expLabel:Label;
		private var expBar:Bar;
		private var levelLabel:Label;
		private var face:Bitmap;

		public function UserFace() {
			super();
			
			var bg:Bitmap = new Bitmap(Global.assetsManager.getAssetsAsBitmapData("user"));
			addChild(bg);
			
			face = new Bitmap();
			var circleMask:Shape = new Shape();
			circleMask.graphics.beginFill(0xFFFFFF);
			circleMask.graphics.drawCircle(0, 0, 25);
//			face.mask = circleMask;
			face.x = 6;
			face.y = 6;
			addChild(face);
			
			nameLabel = new Label(16, 0xFFFFFF, true, "center", true);
			nameLabel.x = 70;
			nameLabel.y = 8;
			addChild(nameLabel);
			
			expBar = new Bar("track_yellow", "bar_bg_1");
			expBar.x = 66;
			expBar.y = 34;
			addChild(expBar);
			
			expLabel = new Label(12, 0xFFFFFF, true, "center", true);
			expLabel.x = 104;
			expLabel.y = 32;
			addChild(expLabel);
			
			levelLabel = new Label(12, 0xFFFFFF, true, "center", true);
			levelLabel.x = 140;
			levelLabel.y = 12;
			addChild(levelLabel);
			
			updateFace("remote/avatar1.png");
		}
		
		public function updateName(data:String):void {
			nameLabel.text = data;
		}
		
		public function updateExp(current:uint, total:uint):void {
			expLabel.text = current + "/" + total;
			expBar.update(current, total);
		}
		
		private function date():void {
		}
		
		public function updateLevel(level:uint):void {
			levelLabel.text = "等级：" + level.toString();
		}
		
		public function updateFace(url:String):void {
			LoaderManager.add(url, LoaderType.IMAGE, faceHandler);
		}
		
		private function faceHandler(data:BitmapData):void {
			face.bitmapData = data;
		}
		
		public function clear():void {
			nameLabel.text = expLabel.text = levelLabel.text = "";
		}
	}
}